<section class="objectpublished panel rounded">
	<h1><?php echo lang('title_entry_published'); ?></h1>
	<form class="table" method="post" action="api/data/published/<?php echo $object->id.'/'.$entry->id;?>">
		<div class="thead">
			<div class="th value"><?php echo lang('heading_value'); ?></div>
			<div class="th actions"><?php echo lang('heading_actions'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<div class="td value">
				<input class="left td" type="checkbox" name="published" <?php if ($entry->published != 0) echo ' checked'; ?> />
			</div>
			<div class="td actions">
				<?php if ($this->user->is_editor()) { ?>
				<a class="left td" href="javascript:void(0);" onClick="$('.objectpublished form').submit();"><?php echo lang('action_update'); ?></a>
				<?php } ?>
			</div>
			<div class="clear"></div>
		</div>
	</form>
</section>

<section class="objectcat panel rounded">
	<h1><?php echo lang('title_entry_category'); ?></h1>

	<form class="table" method="post" action="api/data/category/<?php echo $object->id.'/'.$entry->id;?>">
		<div class="thead">
			<div class="th parent"><?php echo lang('heading_parent'); ?></div>
			<div class="th actions"><?php echo lang('heading_actions'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<div class="td parent">
				<select name="cat_id">
					<option value="null">[none]</option>
					<?php foreach($categories as $cat) { ?>
					<option value="<?php echo $cat->id; ?>" <?php if ($cat->id == $entry->category) echo ' selected'; ?> style="color: <?php echo '#'.$cat->color; ?>;"><?php echo cat_title($cat,$languages); ?></option>
					<?php } ?>
				</select>
			</div>
			<div class="td actions">
				<?php if ($this->user->is_editor()) { ?>
				<a class="left td" href="javascript:void(0);" onClick="$('.objectcat form').submit();"><?php echo lang('action_update'); ?></a>
				<?php } ?>
			</div>
			<div class="clear"></div>
		</div>
	</form>

</section>

<?php $caption_id=0; ?>
<section class="objectentry panel rounded">
	<h1><?php echo lang('title_entry_fields'); ?></h1>
	
	<form class="table" method="post" action="api/data/update/<?php echo $object->id.'/'.$entry->id;?>">
		<div class="thead">
			<div class="th field"><?php echo lang('heading_field'); ?></div>
			<div class="th language"><?php echo lang('heading_language'); ?></div>
			<div class="th value"><?php echo lang('heading_value'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<?php foreach ($fields as $field) { ?> 
				<?php if ($field->type != 'i18n_string') { ?>
				<div class="row">
					<div class="td field">
						<?php echo $field->name; ?>
					</div>
					<div class="td language"></div>
	 
					<div class="td value">
						<?php if ($field->type == 'boolean') { ?>
							<input type="checkbox" name="<?php echo $field->name; ?>" class="type_boolean"<?php if ($entry->{$field->name} != 0) echo ' checked'; ?> />
						<?php } else { ?>
							<input type="text" name="<?php echo $field->name; ?>" class="type_<?php echo $field->type; ?>" value="<?php echo $entry->{$field->name};?>"<?php if ($field->type=='color') echo ' style="background-color: #'.$entry->{$field->name}.';"';?> />
						<?php } ?>						
					</div>
					<div class="clear"></div>
				</div>
				<?php } else { 
					foreach ($languages as $language) { ?>
						<div class="row">
							<div class="td field">
								<?php echo $field->name;?>
							</div>
							<div class="td language">
								<input type="text" name="language" value="<?php echo $language->name; ?>" readonly/>
							</div>
							
							<div class="td value">
								<textarea name="<?php echo $field->name.' '.$language->id; ?>" class="value type_i18n_string"><?php echo $entry->{$field->name.'_'.$language->id}; ?></textarea>
							</div>
							<div class="clear"></div>
						</div>
					<?php }?>
					
				<?php }} ?>
				<div class="new td">
					<?php if ($this->user->is_editor()) { ?>
					<a href="javascript:void(0);" onClick="$('.objectentry form').submit();"><?php echo lang('action_update'); ?></a>
					<?php } ?>
				</div>
				<div class="clear"></div>			
		</div>
	
	</form>
</section>

<section class="objectmedia panel rounded">
	<h1><?php echo lang('title_entry_media'); ?></h1>

	<div class="table">
		<div class="thead">
			<div class="th thumb"><?php echo lang('heading_thumbnail'); ?></div>
			<div class="th filetype"><?php echo lang('heading_filetype'); ?></div>
			<div class="th filesize"><?php echo lang('heading_filesize'); ?></div>
			<div class="th title"><?php echo lang('heading_title'); ?></div>
			<div class="th actions"><?php echo lang('heading_actions'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<?php foreach ($entry->media as $medium) { ?>
			<form id="medium_<?php echo $medium->id; ?>" class="row" method="post" action="api/media/captions/update/<?php echo $medium->id; ?>">
				<div class="td thumb">
					<?php if (is_image($medium->filename)) { ?>
						<a target="_new" href="<?php echo base_url().URBAN_UPLOAD_PATH.$medium->filename; ?>">
							<img class="thumbnail" src="<?php echo base_url().URBAN_UPLOAD_PATH.$medium->filename; ?>" />
						</a>
					<?php } else { ?>
						<a target="_new" href="<?php echo base_url().URBAN_UPLOAD_PATH.$medium->filename; ?>">
							<img class="thumbnail" src="assets/sprites/file.png" />
						</a>
					<?php } ?>
				</div>
				<div class="td filetype">
					<?php echo get_mime_by_extension($medium->filename); ?>
				</div>
				<div class="td filesize">
					<?php $file_info = get_file_info(URBAN_UPLOAD_PATH.$medium->filename); echo format_bytes($file_info['size']); ?>
				</div>
				<div class="td title">
					<?php 
						foreach ($languages as $language) { ?>
						<label for="caption_<?php echo $caption_id;?>"><?php echo "$language->name: "; ?></label>
						<input id="caption_<?php echo $caption_id++; ?>" type="text" value="<?php echo $medium->{'caption_'.$language->id}; ?>" name="<?php echo $language->id; ?>"/>
						<br/>
					<?php } ?>
				</div>
				<div class="td actions">
					<?php if ($this->user->is_editor()) { ?>
					<a href="api/media/delete/<?php echo $medium->id; ?>"><?php echo lang('action_delete'); ?></a>
					<a href="javascript:void(0);" onClick="$('form#medium_<?php echo $medium->id; ?>').submit();"><?php echo lang('action_update_captions'); ?></a>
					<?php } ?>
				</div>
				<div class="clear"></div>
			</form>
			<?php } 
			
			if ($this->user->is_editor()) { ?>
			<div class="row new">
				<?php echo form_open_multipart("api/media/upload/$object->id/$entry->id",'class="td"'); ?>
				
				<input type="file" name="userfile" size="40" />
				
				<a href="javascript:void(0);" onClick="$('.objectmedia .row.new form').submit();"><?php echo lang('action_upload'); ?></a>
				</form>
				<div class="clear"></div>
			</div>
			<?php } ?>
		</div>	
	</div>	

</section>
	
<section class="objecttags panel rounded">
	<h1><?php echo lang('title_entry_tags'); ?></h1>
	
	<form class="table" method="post" action="api/data/tags/<?php echo $object->id.'/'.$entry->id;?>">
		<div class="thead">
			<div class="th tags"><?php echo lang('heading_tags'); ?></div>
			<div class="th actions"><?php echo lang('heading_actions'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<div class="row">
				<div class="td tags">
					<input class="left td" type="text" name="tags" value="<?php echo $entry->tags;?>" /><br/>
				</div>
				<div class="td actions">
					<?php if ($this->user->is_editor()) { ?>
					<a class="left td" href="javascript:void(0);" onClick="$('.objecttags form').submit();"><?php echo lang('action_update'); ?></a>
					<?php } ?>
				</div>
				<div class="clear"></div>
			</div>
		</div>
	</form>
	
</section>

<section class="objectmeta panel rounded">
	<h1><?php echo lang('title_entry_metadata'); ?></h1>
	<div class="table">
		<div class="thead">
			<div class="th name"><?php echo lang('heading_name'); ?></div>
			<div class="th value"><?php echo lang('heading_value'); ?></div>
			<div class="clear"></div>
		</div>
		<div class="tbody">
			<div class="row">
				<div class="td name"><?php echo lang('meta_object'); ?></div>
				<div class="td value"><?php echo $object->table; ?></div>
				<div class="clear"></div>
			</div>
			<div class="row">
				<div class="td name"><?php echo lang('meta_row'); ?></div>
				<div class="td value"><?php echo $entry->id; ?></div>
				<div class="clear"></div>
			</div>
			<div class="row">
				<div class="td name"><?php echo lang('meta_created_by'); ?></div>
				<div class="td value"><?php echo $entry->created_by_email; ?></div>
				<div class="clear"></div>
			</div>
			<div class="row">
				<div class="td name"><?php echo lang('meta_created_on'); ?></div>
				<div class="td value"><?php echo $entry->created_on; ?></div>
				<div class="clear"></div>
			</div>
			<div class="row">
				<div class="td name"><?php echo lang('meta_modified_by'); ?></div>
				<div class="td value"><?php echo $entry->modified_by_email; ?></div>
				<div class="clear"></div>
			</div>
			<div class="row">
				<div class="td name"><?php echo lang('meta_modified_on'); ?></div>
				<div class="td value"><?php echo $entry->modified_on; ?></div>
				<div class="clear"></div>
			</div>
		</div>
	</div>
</section>

<?php if (!$this->user->is_editor()) { ?>
<script>
	$('input,select').attr('readonly','readonly');
</script>
<?php } ?>
